package de.hpi.generationmanager.tesma;

import de.hpi.generator.generator.StartArgs;
import java.io.File;
import java.util.Scanner;
/**
 *
 * @author Michael Wolowyk
 */
public class TesmaGenerator {

    public static void generateData(StartArgs aStartArgs) throws Exception {
        Process process = createTesmaProcess(aStartArgs);
        process.waitFor();
        printTesmaOutput(process);
    }

    private static void printTesmaOutput(final Process process) throws InterruptedException {
        Scanner scanner = new Scanner(process.getInputStream());
        while (scanner.hasNextLine()) {
            System.out.println(scanner.nextLine());
        }
        scanner.close();
    }

    private static Process createTesmaProcess(StartArgs aStartArgs) throws Exception {
        ProcessBuilder processBuilder = new ProcessBuilder(new File("dbtesma\\dbtesma.exe").getAbsolutePath(), "--offsets", "-f", new File(aStartArgs.getConfigPath()).getName());
        processBuilder.directory(new File(aStartArgs.getOutputPath()));
        return processBuilder.start();
    }
}
